package AssembleExercise;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class HomeWork2 {
    public static void main(String args[])
    {
        List<Car> list = new ArrayList<>();
        list.add(new Car("奥迪",5649656));
        list.add(new Car("宝马",2316546));
        list.add(new Car("大众",2315623));
        list.add(new Car("奔驰",4687985));
        list.add(new Car("法拉利",897856153));
        //list.remove(3);
//        boolean b = list.contains(new Car("大众", 2315623));
//        System.out.println(b);
        List<Car> list1 = new ArrayList();
        list1.add(new Car("保时捷",5648));
        list.addAll(list);
        for(Car c:list)
        {
            System.out.println(c);
        }

    }
}

class Car
{
    private String name;
    private int price;

    public Car() {
    }

    public Car(String name, int price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return name+","+price;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Car car = (Car) o;
        return price == car.price &&
                Objects.equals(name, car.name);
    }

    @Override
    public int hashCode() {

        return Objects.hash(name, price);
    }
}
